//
//  UIScrollView+RAC.m
//  高仿暴走斗图
//
//  Created by key on 16/5/4.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "UIScrollView+RAC.h"
#import "UIScrollView+RACSignal.h"

@implementation UIScrollView (RAC)

+ (UIScrollView *)rac_createScrollViewForContentOffset:(CGPoint)contentOffset andContentSize:(CGSize)contentSize canPagingEnabled:(BOOL)pagingEnabled canScrollEnabled:(BOOL)scrollEnabled canBounces:(BOOL)bounces withCompletion:(void(^)(id x))completion {
 
    return [[self alloc] initWithRAC_createScrollViewForContentOffset:contentOffset
                                                       andContentSize:contentSize
                                                     canPagingEnabled:pagingEnabled
                                                     canScrollEnabled:scrollEnabled
                                                           canBounces:bounces
                                                       withCompletion:completion];
}

- (UIScrollView *)initWithRAC_createScrollViewForContentOffset:(CGPoint)contentOffset andContentSize:(CGSize)contentSize canPagingEnabled:(BOOL)pagingEnabled canScrollEnabled:(BOOL)scrollEnabled canBounces:(BOOL)bounces withCompletion:(void(^)(id x))completion {
    
    if (self = [super init]) {
        
        self.contentOffset = contentOffset;
        self.contentSize = contentSize;
        self.pagingEnabled = pagingEnabled;
        self.scrollEnabled = scrollEnabled;
        self.bounces = bounces;
        
        [[[self rac_didScroll] deliverOn:[RACScheduler mainThreadScheduler]] subscribeNext:^(id x) {
            if (completion) {
                completion(x);
            }
        }];
    }
    return self;
}

@end
